import { FormatCreateTime } from "../filter/time";

import {
  ORDER_STATUS,
  ORDER_TYPE,
  PAY_TYPE_ARRAY,
  PLATEFORM_ORDER_TYPE_ARRAY,
} from "../contanst/data";
export default {
  FormatCreateTime: FormatCreateTime,
  formatNull(value) {
    if (value === undefined || value === null || value === "") {
      return "暂无";
    } else {
      return value;
    }
  },
  formatLongText(value) {
    if (value === undefined || value === null || value === "") {
      return "暂无";
    } else if (value.length > 8) {
      return value.substr(0, 8) + "...";
    } else {
      return value;
    }
  },
  formatPayType(value) {
    return PAY_TYPE_ARRAY[value];
  },

  formatOrderType(value) {
    return ORDER_TYPE[value];
  },

  formatSourceType(value) {
    return PLATEFORM_ORDER_TYPE_ARRAY[value];
  },

  formatStatus(value) {
   
    return ORDER_STATUS[Number(value) + 1];
  },
  formatPayStatus(value) {
    if (value === 0) {
      return "未支付";
    } else if (value === 4) {
      return "已退款";
    } else {
      return "已支付";
    }
  },
  formatDeliverStatus(value) {
    if (value === 0 || value === 1) {
      return "未发货";
    } else {
      return "已发货";
    }
  },
  formatProductAttr(value) {
    if (value == null) {
      return "";
    } else {
      let attr = JSON.parse(value);
      let result = "";
      for (let i = 0; i < attr.length; i++) {
        result += attr[i].key;
        result += ":";
        result += attr[i].value;
        result += ";";
      }
      return result;
    }
  },
}